<template>
  <div class="app-container">
    <!-- 创建数据 -->
    <k-button class="top-btn" value="添加数据" @click.native="creatActivityDialog" />
    <!--表格相关 -->
    <el-table
      :data="bloodTableData"
      fit
      highlight-current-row
      style="width: 100%;border-radius:8px;"
      :header-cell-style="{ background: '#F6F5FA', color: '#4E4F62' }"
    >
      <el-table-column prop="dictId" width="80px" type="index" label="数据编号" align="center" />
      <el-table-column prop="dictLabel" label="字典标签" align="center" show-overflow-tooltip />
      <el-table-column prop="dictValue" label="字典键值" align="center" show-overflow-tooltip />
      <el-table-column prop="type" label="字典基本类型" align="center" show-overflow-tooltip />
      <el-table-column prop="dictSort" label="排序" align="center" show-overflow-tooltip />
      <el-table-column label="数据状态" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-tag :type="scope.row.status != 1? 'danger':''">{{ scope.row.status == 1 ? '正常' : '禁用' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" align="center" show-overflow-tooltip />
      <el-table-column prop="createTime" label="创建时间" align="center" show-overflow-tooltip />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <div class="op-div">
            <k-button class="table-btn" value="查看/修改" @click.native="updateActivityDialog(scope.row)" />
            <k-button
              class="table-btn"
              value="删除"
              :disabled="scope.row.activityStatus === 1 ? true : false"
              @click.native="deleteActivityItem(scope.row.dictCode)"
            />
            <!-- <k-button class="table-btn" value="板块排序" @click.native="activitySortDialog(scope.row)" /> -->
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="totalRows > 0"
      :total="totalRows"
      :page.sync="listQuery.pager.pageNo"
      :limit.sync="listQuery.pager.pageSize"
      @pagination="loadData"
    />

    <!-- 创建数据 弹窗 -->
    <k-dialog
      :show-hide.sync="creatActivity.showHide"
      :modal-append-to-body="false"
      :append-to-body="true"
      :title="textMap[dialogStatus]"
      class-name="creatActivity_dialog"
      :show-foot="false"
      :two-btn="true"
      :close-fun="handleCloseDialog"
      @click="saveActivity"
    >
      <div class="dialog-giveBabySetting">
        <div style="width: 500px !important">
          <el-form ref="ruleForm" label-width="100px" :model="dictData">
            <el-form-item label="数据类型：">
              <el-input v-model="dictData.dictType" disabled show-word-limit placeholder="请输入数据类型" />
            </el-form-item>
            <el-form-item label="数据名称：">
              <el-input v-model="dictData.dictLabel" show-word-limit placeholder="请输入数据名称" />
            </el-form-item>
            <el-form-item label="数据键值：">
              <el-input v-model="dictData.dictValue" show-word-limit placeholder="请输入数据键值" />
            </el-form-item>
            <el-form-item label="显示排序：">
              <!-- <el-input v-model="" show-word-limit placeholder="" /> -->
              <el-input-number v-model="dictData.dictSort" label="请输入数据键值" />
            </el-form-item>
            <el-form-item label="数据状态：">
              <el-radio-group v-model="dictData.status">
                <el-radio label="1">正常</el-radio>
                <el-radio label="2">禁用</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="数据基本类型：">
              <el-radio-group v-model="dictData.type">
                <el-radio label="String">String</el-radio>
                <el-radio label="Number">Number</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="备注：">
              <el-input v-model="dictData.remark" type="textarea" :rows="3" show-word-limit placeholder="请输入" />
            </el-form-item>
          </el-form>
        </div>
      </div>
    </k-dialog>
  </div>
</template>
<script>
import { DictDetailsList, DictDetailsSaveSysDictData, DetailsUpdateeSysDictData, DictDetailsdelete } from '@/api/dict/index'
import Pagination from '@/components/Pagination'

export default {
  components: {
    Pagination
  },
  data() {
    return {
      dialogStatus: 'create',
      textMap: {
        update: '修改数据类型',
        create: '创建数据类型'
      },
      totalRows: 0, // 分页组件--数据总条数
      listQuery: {
        pager: {
          pageNo: 1,
          pageSize: 10,
          totalRows: '',
          start: ''
        },
        dictType: undefined
      },
      bloodTableData: [],
      updateBabyNum: {
        showHide: false
      },
      dictData: {
        dictId: undefined,
        status: '1',
        dictSort: 0,
        type: undefined,
        dictLabel: undefined,
        dictValue: undefined,
        remark: undefined,
        dictType: undefined
      },
      creatActivity: {
        showHide: false
      },
      actDialogShowHide: false,
      ruleGuide: {
        showHide: false
      }
    }
  },

  created() {
    this.loadData()
  },
  methods: {

    // 关闭修改弹窗
    handleNumCloseDialog() {
      this.updateBabyNum.showHide = false
    },

    /** ************/

    loadData() {
      this.listQuery.dictType = this.$route.query.dicttype
      console.log(this.$route.query.dicttype)
      DictDetailsList(this.listQuery).then(res => {
        this.totalRows = res.data.totalRows
        this.bloodTableData = res.data.rows
      })
    },

    // 添加数据
    creatActivityDialog() {
      this.$resetForm(this.dictData)
      this.dictData.dictType = this.$route.query.dicttype
      this.dictData.status = '1'
      this.dictData.dictSort = 0
      this.dictData.type = 'Number'
      this.dialogStatus = 'create'
      this.creatActivity.showHide = true
    },

    updateActivityDialog(row) {
      console.log(row)
      this.dialogStatus = 'update'
      this.creatActivity.showHide = true
      this.dictData = { ...row }
    },
    addDialog(type) {
      console.log(type)
    },
    // 保存数据
    saveActivity() {
      if (this.dialogStatus === 'update') {
        DetailsUpdateeSysDictData(this.dictData).then((res) => {
          console.log(res)
          if (res.data.success) {
            this.creatActivity.showHide = false
            this.loadData()
          } else this.$message.error(res.data.msg)
        })
      } else {
        DictDetailsSaveSysDictData(this.dictData).then((res) => {
          console.log(res)
          if (res.data.success) {
            this.creatActivity.showHide = false
            this.loadData()
          } else this.$message.error(res.data.msg)
        })
      }
      // this.handleCloseDialog()
    },

    // 重新获取
    reset() {
      this.loadData()
    },

    handleCloseDialog() {
      this.creatActivity.showHide = false
      this.$nextTick(() => {

      })
    },
    deleteActivityItem(dictId) {
      const dictCodes = [dictId]
      this.$confirm('确定删除么?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        DictDetailsdelete({
          dictCodes
        }).then(res => {
          if (res.data.success) {
            this.$message.success('删除成功')
            this.loadData()
          } else {
            this.$message.error(res.data.msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },

    // 搜索查询事件
    handleFilter() {
      this.listQuery.pager.pageNo = 1
      this.loadData()
    }
  }
}
</script>
<style lang="scss" scoped>
$menuText: #14162E; // 侧边栏字体颜色
$hoverColor: #1D143C; // 鼠标停留主色调浅色
$mainColor: #3b425d; // 主色调

.synthesis-box {
  ::v-deep .el-select .el-select__tags>span {
    display: none;
  }

  .el-tag+.el-tag {
    margin-left: 10px;
  }

  .el-tag {
    color: $mainColor;
    background-color: #ffffff;
    border-color: $mainColor;

    ::v-deep .el-tag__close {
      color: $mainColor;
    }

    ::v-deep .el-icon-close:hover {
      color: #ffffff;
      background: $mainColor;
    }
  }

  .flex {
    display: flex;

    .el-form-item {
      .el-select {
        width: 120px;
        margin-right: 10px;
      }
    }
  }
}

.filter-container {
  width: 100%;
  height: 48px;
  line-height: 48px;

  .filter-item {
    display: inline-block;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .kInput {
    position: absolute;
    right: 20px;
  }

  .filter-title {
    height: 48px;
    line-height: 48px;
    font-size: 16px;
    font-weight: 500;
    margin-right: 22px;
    color: #14162E;
  }

  .user-item {
    margin-left: 10px;
    margin-right: 20px;
  }

  .room-type,
  .user-status,
  .account-status {
    margin-right: 20px;
  }
}

.red_money {
  width: 200px;
}

.grid-div {
  display: grid;
  grid-template-columns: repeat(7, 120px);

  .item {
    height: 50px;
    font-size: 14px;
    line-height: 50px;
    text-align: center;
    border: 1px solid #E3E2E7;
    width: 120px;
    overflow: hidden;
    display: inline-block;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 10px;
  }
}

.top-btn {
  margin: 30px 0px 30px 0px;
  font-size: 14px;
  color: #ffffff;

  &:nth-of-type(2) {
    margin-left: 10px;
  }
}

.kSelect .el-select .el-input .el-input__inner {
  width: 124px;
}

::v-deep .el-select .el-input.is-focus .el-input__inner {
  border-color: $mainColor;
}

::v-deep .el-input__inner:focus {
  border-color: $mainColor;
}

.el-form-item__label-wrap .el-form-item__label {
  float: none;
}

.dialog_creatActivity {
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin: 40px 80px;

  ::v-deep .el-select .el-select__tags>span {
    display: none;
  }

  ::v-deep .el-range-editor.el-input__inner {
    width: 400px;
  }

  .el-tag+.el-tag {
    margin-left: 10px;
  }

  .el-tag {
    color: $mainColor;
    background-color: #ffffff;
    border-color: $mainColor;

    ::v-deep .el-tag__close {
      color: $mainColor;
    }

    ::v-deep .el-icon-close:hover {
      color: #ffffff;
      background: $mainColor;
    }
  }
}

.form-modify {
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin: 10px 80px;
}

.editer {
  width: 500px;
  border-radius: 8px;
  float: left;
  box-sizing: border-box;
  color: #606266;

  ::v-deep .ql-container {
    height: 270px;
    border-radius: 0px 0px 8px 8px;
  }

  ::v-deep .ql-toolbar.ql-snow {
    border-radius: 8px 8px 0px 0px;
  }
}

.chargeform {
  display: flex;
  flex-direction: row;
}

::v-deep .el-switch__label.is-active {
  color: $mainColor;
}

.addBox_dialog {
  display: flex;
  flex-direction: column;
  justify-content: center;

  ::v-deep .el-dialog__body {
    width: 678px;
    margin: 40px 80px;
  }

  ::v-deep .el-select .el-select__tags>span {
    display: none;
  }

  .el-tag+.el-tag {
    margin-left: 10px;
  }

  .el-tag {
    color: $mainColor;
    background-color: #ffffff;
    border-color: $mainColor;

    ::v-deep .el-tag__close {
      color: $mainColor;
    }

    ::v-deep .el-icon-close:hover {
      color: #ffffff;
      background: $mainColor;
    }
  }
}

.cell-baby {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;

}

.ellipsis-span {
  width: 80px;
  overflow: hidden;
  display: inline-block;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.giveBaby-dialog {
  ::v-deep .el-dialog__body {
    width: 678px;
    height: 500px;
  }

  .dialog-giveBabySetting {
    ::v-deep.el-input {
      width: 200px;
    }

    .price-input {
      width: 120px;
    }
  }
}

.actdiv {
  padding: 50px;
}

.actdiv>* {
  margin-right: 20px
}
</style>
